PDA

View Full Version : onclick Redirect from form entry - need help



DowntownEER
05-06-2006, 06:17 PM
Hi. I'm trying to build a form that redirects to a page extension matching an input value. (Looking at my code will probably make that more clear.)

When I click on my submit button, nothing happens. Can anybody help? Thanks!

I have this short script in the <head>

<script>
function sendit(){
point = document.ProfitPoint.code.value.toLowerCase()
window.location(" 'http://blurrline.com/'+point+'/htm' "
}
</script>

My url's are case sensitive, so I need the lowercase conversion.

Here's the form code that's in the <body>

<form name="ProfitPoint">
Enter Code:
<input type="text" name="code" size="15">
<input type="button" value="Submit" onClick="sendit()">
</form>

Twey
05-06-2006, 06:29 PM
That's because your code is a mangled, inaccessible, vastly over-complicated mess.
<form action="" method="get" onsubmit="this.action = this.elements['code'].value.toLowerCase(); return true;">
<fieldset>
<legend>Code entry form</legend>
<input type="text" name="code" id="code" size="15">
<label for="code">Enter Code:</label>
<input type="submit" value="Submit">
</fieldset>
</form>

DowntownEER
05-06-2006, 06:32 PM
And, here I thought it just needed a tweak. Thanks! http://img332.imageshack.us/img332/6944/roll8hi.gif

Twey
05-06-2006, 06:33 PM
No problem :)
Oh, for future reference:
1) input type="submit" is more accessible than input type="button", and should be used where possible;
2) same for onsubmit vs. onclick;
3) the type attribute of the script element is required, as are action and method for form;
4) labels are greatly superior to any other methods of labelling an element, and also produce cleaner markup;
5) window.location is a property, not a method; direct setting should really be done using window.location.href;
6) you only need to enclose strings in one set of quotes;
7) you should always use the document.forms collection to reference forms, rather than assuming that they will always be available as properties of the same name under document.

The fieldset wasn't really necessary, but I have a tendency to overdo things. :)

DowntownEER
05-06-2006, 06:39 PM
With trepidation...

It's redirecting to this extension: menu?code=menu

I'm working off of a static html page and want it to redirct to "http://blurrline.com/"+code+".htm"

Twey
05-06-2006, 06:43 PM
Apologies, I missed the .htm extension. You can safely ignore the question mark and everything after it; if you're using a static page, it will have no effect whatsoever.
<form action="" method="get" onsubmit="this.action = 'http://blurline.com/' + this.elements['code'].value.toLowerCase() + '.htm'; return true;">
<fieldset>
<legend>Code entry form</legend>
<input type="text" name="code" id="code" size="15">
<label for="code">Enter Code:</label>
<input type="submit" value="Submit">
</fieldset>
</form>

DowntownEER
05-06-2006, 06:46 PM
Thanks. I really appreciate the fast help. And the lessons.

I self-taught html, but this is tougher.

Twey
05-06-2006, 06:50 PM
I self-taught html, but this is tougher.Yeah... I started that way myself. You go along, thinking you know everything, then you step out into the world and find that just because it looks OK when you view it, doesn't mean it's a good page. There are these things called "standards" to adhere to, that make your page work in other browsers, and the way you've been doing everything for three years is painfully, humiliatingly, and undeniably wrong.

Sorry, I'm in a strange mood today. :)