PDA

View Full Version : onChange do doc.write



Rockonmetal
10-01-2007, 10:59 PM
Ok, just to put it out there. I am awful at javascript... seriously...
I have this form where users can create a new page...
This is where the user selects what type of page he would like to create.


<p>
<label for="pType">Page Type:</label>
<select name="pType">
<option value="HTML">HTML</option>
<option value="PHP">PHP</option>
</select>
</p>

I would like to have it so when the user selects HTML it adds .html where .ext is:

<p>
<label for="pName">Page Name:</label>
<input type="text" name="pName" />.ext
</p>
If user selects PHP then it adds .php to the same place.

I don't know how todo this at all as I mentioned at top...
I haven't used javascript in a long time, like 5 months, and I didn't even really know it then...
Thanks to all who help!

djr33
10-01-2007, 11:28 PM
<div id="ext">.ext</div>
onChange="document.getElementByID('ext').innerHTML = '.php';"

Rockonmetal
10-02-2007, 01:22 AM
k thnx i'll try it out

Rockonmetal
10-02-2007, 01:25 AM
I entered the code like this:

<p>
<label for="pType">Page Type:</label>
<select name="pType">
<option value="HTML" onChange="document.getElementByID('ext').innerHTML = '.html;">HTML</option>
<option value="PHP" onChange="document.getElementByID('ext').innerHTML = '.php';">PHP</option>
</select>
</p>
<p>
<label for="pName">Page Name:</label>
<input type="text" name="pName" /><div id="ext"></div>

</p>
It didn't work... I don't think i entered it right though...

tech_support
10-02-2007, 01:29 AM
It's a little bit different with select boxes. Changes are highlighted.


<p>
<label for="pType">Page Type:</label>
<select name="pType" onchange="document.getElementById('ext').innerHTML = this.options[this.selectedIndex].value">
<option value="HTML">HTML</option>
<option value="PHP">PHP</option>
</select>
</p>
<p>
<label for="pName">Page Name:</label>
<input type="text" name="pName" /><div id="ext"></div>

</p>

Rockonmetal
10-02-2007, 01:32 AM
Its still doesn't work..
I tried it in firefox and IE 7 and it doesn't work...
I mean it would make perfect sense that it would work after that little fix... but Idk why... maybe my computer is deciding not to do that :D