[thelist] changing submit button value with javascript

E Michael Brandt michael at divaHTML.com
Tue Jul 31 17:44:19 CDT 2007


A few things I see:

First,  if (clickedID.checked == true) can not work, as "clickedID" here 
is a string, and not an object.  The simplest thing is to change this

<input type="checkbox" name="delasset" id="delasset0"
 > onclick="toggleValue('submit0','delasset0','Save','Del');" />

to this:

input type="checkbox" name="delasset0" id="delasset0"> 
onclick="toggleValue('submit0','Save','Del');" />

(note I also edited the "name" attribute to equal the id attribute.)


and then change this:


function toggleValue(toggleID,clickedID,val1,val2)
     {
         if (clickedID.checked == true)


to this:


function toggleValue(toggleID,val1,val2)
     {
         if (this.checked)



Next, what is this?:

<input type="checkbox" name="delasset" id="delasset0"> 
onclick="submit0.value = 'Del';" />


Lose it.


Does that work?

-- 

E. Michael Brandt

www.divaHTML.com
divaGPS : you-are-here menu highlighting
divaFAQ : FAQ pages with pizazz

www.valleywebdesigns.com
JustSo PictureWindow
JustSo PhotoAlbum

--


Joel D Canfield wrote:
> I'm trying to change the value of a submit button with javascript. when
> the 'delete this item' checkbox is clicked, I want to toggle the value
> of the submit button to 'Del', and when it's clicked again, toggle it
> back to 'Save'
> 
> all that happens is the submit button is selected, but not changed
> 
> here's how I'm calling the function
> 
>     <input type="checkbox" name="delasset" id="delasset0"
> onclick="toggleValue('submit0','delasset0','Save','Del');" />
> 
> here's submit0
> 
>     <input type="submit" name="submit" id="submit0" value="Save"
> class="updformsubmit" />
> 
> and here's the javascript
> 
>     function toggleValue(toggleID,clickedID,val1,val2)
>     {
>         if (clickedID.checked == true)
>         {
>             document.getElementById(toggleID).value = val2;
>         } else {
>             document.getElementById(toggleID).value = val1;
>         }
>     }
> 
> this works to change the value when the checkbox is clicked, but of
> course doesn't change it back, ever
> 
>     <input type="checkbox" name="delasset" id="delasset0"
> onclick="submit0.value = 'Del';" />
> 
> what am I missing?
> 
> thanks
> 
> joel




More information about the thelist mailing list