Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with input text link to url

Status
Not open for further replies.

slickyboi

Programmer
Oct 16, 2003
29
0
0
US
I am trying to create a input text box when a user enters in his/hers room number and submits it, it will send them to a specific url map. There will be a list of numbers and each one will link to a certain url. But I am pretty much a newb when it comes to javascript so if anyone has any suggestions on how I might be able to incorporate into the vaildation script below I would truly appreciate it.

<HTML>
<HEAD>
<TITLE>Untitled Page</TITLE>
<META http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;>


<SCRIPT LANGUAGE=&quot;JavaScript&quot;>

function validateroom(field) {
var valid = &quot;0123456789-&quot;;
var hyphencount = 0;

if (field.length!=4 && field.length!=10) {
alert(&quot;Invalid characters in your room number.&quot;);
return false;
}
for (var i=0; i < field.length; i++) {
temp = &quot;&quot; + field.substring(i, i+1);
if (temp == &quot;-&quot;) hyphencount++;
if (valid.indexOf(temp) == &quot;-1&quot;) {
alert(&quot;Invalid characters in your room number. Please try again.&quot;);
return false;
}
if ((hyphencount > 1) || ((field.length==10) && &quot;&quot;+field.charAt(5)!=&quot;-&quot;)) {
alert(&quot;The hyphen character should be used with a properly formatted 4 digit room humber, like '1234'. Please try again.&quot;);
return false;
}
}
return true;
}
// End -->
</script>


</HEAD>


<form name=room onSubmit=&quot;return validateroom(this.room.value)&quot;>
Room #: <input type=text size=5 name=room>
<input type=submit value=&quot;Submit&quot;>
</form>



</BODY>
</HTML>
 
hi,
so we meet again its pretty simple,
in ur code add this:
}
return true;
location.href=&quot;HTMLPage&quot;+numberFromField+&quot;.html&quot;
//if number entered is 10 this will give HTMLPage10.html and redirect it to that page
}


and second of all u seem to be validating some numbers can u give me the format that u want? i can give u a shorter method to validate it...


Known is handfull, Unknown is worldfull
 
Hehehe,

Thx vbkris!

I wanted to write the script so it will be like:

if room number is btwn (1200-1800) = if room number is btwn (2200-2800) = if room number is btwn (3200-3800) =
And the validation script won't allow any letters and it has to be no more than 4 digits.
 
}
return true;
location.href=&quot;HTMLPage&quot;+numberFromField+&quot;.html&quot;
//if number entered is 10 this will give HTMLPage10.html and redirect it to that page
}


I added this to the code but it's not working.. Am I not doing something right?
 
add this code:
}
return true;
//instead of location.href=&quot;HTMLPage&quot;+numberFromField+&quot;.html&quot;
if(roomnumber>1200 && roomnumber<1800)
{
location.href=&quot;}
//repeat it for others...
}



and as for ur validation:
if (!field.macth(/^[\d]{4}$/)) {
alert(&quot;Invalid characters in your room number.&quot;);
return false;
}
//This will allow the user to enter only 4 numbers...


Known is handfull, Unknown is worldfull
 
sweetness ,, thx vbkris

When I hit the submit button it doesnt seem to go anywhere tho..Do you think I need to rewrite my form script in order for it to link properly?


<form name=room onSubmit=&quot;return validateroom(this.room.value)&quot;>
Room #: <input type=text size=5 name=room>
<input type=submit value=&quot;Submit&quot;>
</form>
 
Would you be able to look over my script to see what I might have done wrong?

<HTML>
<HEAD>
<TITLE>Untitled Page</TITLE>
<META http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;>


<SCRIPT LANGUAGE=&quot;JavaScript&quot;>

function validateroom(field) {
var valid = &quot;0123456789-&quot;;
var hyphencount = 0;

if (!field.macth(/^[\d]{4}$/)) {
alert(&quot;Invalid characters in your room number.&quot;);
return false;
}
//This will allow the user to enter only 4 numbers...

for (var i=0; i < field.length; i++) {
temp = &quot;&quot; + field.substring(i, i+1);
if (temp == &quot;-&quot;) hyphencount++;
if (valid.indexOf(temp) == &quot;-1&quot;) {
alert(&quot;Invalid characters in your room number. Please try again.&quot;);
return false;
}
if ((hyphencount > 1) || ((field.length==10) && &quot;&quot;+field.charAt(5)!=&quot;-&quot;)) {
alert(&quot;The hyphen character should be used with a properly formatted 4 digit room humber, like '1234'. Please try again.&quot;);
return false;
}
}
return true;

if(roomnumber>1200 && roomnumber<1800)
{
location.href=&quot;}
//repeat it for others...
}
if(roomnumber>2200 && roomnumber<2800)
{
location.href=&quot;}
//repeat it for others...
}
if(roomnumber>3200 && roomnumber<3800)
{
location.href=&quot;}
//repeat it for others...
}
// End -->
</script>


</HEAD>


<form name=room onSubmit=&quot;return validateroom(this.room.value)&quot;>
Room #: <input type=text size=5 name=room>
<input type=submit value=&quot;Submit&quot; onClick=&quot;validateroom(this.room.value)&quot;>
</form>



</BODY>
</HTML>
 
Can anyone look over my code to see what I have done wrong... Arrghh I know its probably something easy that I am overlooking but it doesnt seem to be going anywhere when I click the submit button...
 
hi,
remove the return true; before the if conditions:
return true; //remove this

if(roomnumber>1200 && roomnumber<1800)
{
location.href=&quot;}
//repeat it for others...
}


Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top