Page 1 of 1
Can you make spinner buttons in PHP?
Posted: Thu Jan 07, 2010 2:42 pm
by OldRod
I've been looking and can't find any examples of using spinner buttons on a form with PHP.
Anyone done this? Does it require javascript? Or can it be done in PHP?
Re: Can you make spinner buttons in PHP?
Posted: Thu Jan 07, 2010 3:50 pm
by OldRod
Ok, I found an example using JS, but I can't get it to work.
Here's the code I'm trying (snipped from a larger part obviously):
Code: Select all
<td rowspan=2>Strength: <input type="text" name="str" value=20 size=2></td>
<td><input type="button" value="+" onclick="this.form.str.value++;"></td>
<td><input type="button" value="-" onclick="this.form.str.value--;"></td>
It looks fine on screen, but clicking the button does nothing.
Do I need to do something to activate the code somehow? I've never tried putting Javascript inside of form element before so there's probably something I'm missing.
Re: Can you make spinner buttons in PHP?
Posted: Thu Jan 07, 2010 4:06 pm
by Falken
You can try this:
Give the text field an ID, like this
Code: Select all
<input type="text" value="" id="myBox" />
And to change the value of the box with a button
Code: Select all
<input type="button" value="Hello" onClick="javascript: document.getElementById('myBox').value = 'hello world';" />
Use that and you can probably make your own spin box
Re: Can you make spinner buttons in PHP?
Posted: Thu Jan 07, 2010 4:15 pm
by OldRod
Code: Select all
<td><input type="text" id="str" value=20 size=2></td>
<td><input type="button" value="+" onclick="javascript: document.getElementById('str').value++;"></td>
This works - thanks Falken! It's not exactly what you posted, but it pointed me in the right direction
