Forum Moderators: open

Message Too Old, No Replies

Replace text in form

         

Ddms

5:00 pm on Oct 5, 2009 (gmt 0)

10+ Year Member


Hello, I have a simple one text field form that will have a filename inserted. It will be something like filename.jpg. When the submit button is clicked, it will become the URL address and I need the .jpg extension to become .php. How do I do this?

Here's what I have in the head section:

<script type="text/javascript">
<!--
function handleThis(formElm)
{
window.location="http://website.com/"+formElm.number.value+"";
return false;
}
// -->
</script>

and my form:
<form onsubmit="return handleThis(this)">
<input type="text" value="filename.jpg" name="number" />
<input type="submit" value="Submit" />
</form>

As it is, when the submit button is selected, the browser opens page http://website.com/filename.jpg and I need it to be http://website.com/filename.php

Help please?

daveVk

2:04 am on Oct 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



window.location="http://website.com/"+formElm.number.value+"";

becomes

window.location="http://website.com/"+formElm.number.value.split(".")[0]+".php";

that will change all extensions, change "." to ".jpg" if required

Ddms

2:33 am on Oct 6, 2009 (gmt 0)

10+ Year Member



Thank you so much! Works perfectly :)