Forum Moderators: open
Thanks
For example:
<script>
function convertURL() {
var url = document.getElementsByName( "url")[0];
var fullurl = document.getElementsByName( "fullurl")[0];
fullurl.value = "http://www"+ url.value +".com";
}
</script>
<form ... onSubmit='convertURL();'>
Your URL: <input name='url' type='text'><input name='fullurl' type='hidden'><br>
<input type='submit'>
</form> Now when you hit submit that should expand the URL the user typed, and stick it into the hidden input field.
You can't submit to http://www.example.com
You can submit to http://www.example.com/mypage.pl
To change the location of the form's target you could change the function to look like this:
function convertURL() {
var url = document.getElementsByName( "url")[0];
var fullurl = document.getElementsByName( "fullurl")[0];
fullurl.value = "http://www"+ url.value +".com";
alert( "Old form target "+document.(name of form).action);
document.(name of form).action = fullurl.value;
alert( "New form target "+document.(name of form).action);
}
Can't remember if that's the right way to do it but the alert's will tell you. Take them out if it's working!
The syntax is slightly different in JavaScript, rather than modifying the calling string, it's a function that returns the new string.
Try:
document.(form name).(input name).value = document.(form name).(input name).value.replace( /\s/g, "");
\s means any whitespace, so better to use it just incase there's something unexpected in there.
<script>
function convertURL() {
document.go.url.value = document.go.url.value.replace( /\s/g, "");
var url = document.getElementsByName( "url")[0];
var fullurl = document.getElementsByName( "fullurl")[0];
fullurl.value = "http://www."+ url.value +".com";
msg = document.go.url.value +"?"
return confirm(msg);
}
</script>
<form name= "go" onsubmit='convertURL();location.href=fullurl.value;return false'>
<input name='url' type='text' /> <input name='fullurl' type='hidden' />
<input type='submit' value=" Go " />
</form>
Thanks so much for your help!
[edited by: HighPriestess at 10:27 pm (utc) on Oct. 25, 2007]