Hello,
I am fairly new to coding and have come across something I cannot figure out. My page has a text box for a zip code then a drop down list that will take the user to a specific application page. I got the code working correctly for the form redirect and to pass the zip code that is entered in the text box. My problem is this: If the user does not enter a zip code the current text box value "Enter Zip Code" is passed along, which our application won't accept so the page results in a Site Error.
I need to know how to replace the current field value with nothing if the user does not enter a zip code. We do not want to force them to enter a zip. The pages are ASPX.
My code looks like this so far:
with the text field set up this way:
Thank You so much for your help
I am fairly new to coding and have come across something I cannot figure out. My page has a text box for a zip code then a drop down list that will take the user to a specific application page. I got the code working correctly for the form redirect and to pass the zip code that is entered in the text box. My problem is this: If the user does not enter a zip code the current text box value "Enter Zip Code" is passed along, which our application won't accept so the page results in a Site Error.
I need to know how to replace the current field value with nothing if the user does not enter a zip code. We do not want to force them to enter a zip. The pages are ASPX.
My code looks like this so far:
Code:
<script runat="server"> string zip_code; public void Page_Load(Object sender, EventArgs e) { string script = "function redirectMenu(){var zip=document.getElementById('zip_code'); var location=document.redirect.menu.options[document.redirect.menu.selectedIndex].value; if (zip.value != null) location=location+'&ZipCode='+zip.value; window.location.href=location;}"; Page.ClientScript.RegisterClientScriptBlock( this.GetType(), "redirectMenu", script, true ); } </script>
with the text field set up this way:
Code:
<input id="zip_code" type="text" tabindex="1" size="18" onfocus="javascript:this.value=''; this.maxLength='5';" value="Enter Zip Code" class="formtext" />
Comment