SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to change button label without changing "value" attribute?

    I have the following input tags that create two buttons with the labels of "Save" and "Preview". When either button is pressed the same form is submitted and the "action" variable will have the apprpriate value depending on which button was pressed.

    Code:
    <input type="submit" name="action" value="Save" style="width:150px;">
    <input type="submit" name="action" value="Preview" style="width:150px;">
    Is it possible to redesign this code so that the buttons can have different labels, but the "action" variable will have the same values?

    In other words, I can't change the "Save" or "Preview" values for the action variable, but I need to display a different label on the button!

    Thanks for any help.

  2. #2
    (****** or Deleted)
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After checking at w3schools I do not believe this is possible sorry...

    http://www.w3schools.com/tags/tag_input.asp

    Can you not change the values, as well as the corresponding script that is checking the variables?

  3. #3
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Isn't there any way? I sure hope so..

    I need to be able to change the button label without having to change the script code because I must allow multiple languages. If someone wants to translate the button into French, then I can't make them change the script, too.. way too complicated.

    Is it possible to dynamically set the "action" value with javascript or something? ie: You click the button, it executes some javascript code that sets the value of action to whatever and then submits..

    Anyone?

  4. #4
    (****** or Deleted)
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately javascript is my one of my major weaknesses, so hopefully someone else can answer this... I am sure it is possible though...

    Sorry I cannot be any more helpful than that

  5. #5
    SitePoint Member
    Join Date
    Aug 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure I'm following this, in particular, why the name has to be the same. I would think the two buttons could be designed to do different things if you call two different actions on the onclick event. But I'm not clear on what we're trying to do ...

  6. #6
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The two buttons are input tags of the same form. The script that is executed when the form is submitted looks to the value of the action variable to determine what it is supposed to do.. either save or preview.

    The problem I have is:

    1. I need to easily be able to change the button labels, because people will want to use different languages.

    2. The action of the script depends on the "action" value of the button.. which I can't change because of point 1.

    So I'm stuck.. I figured that what I might be able to do is allow people to change the action value for the button, but then use javascript to set it back to either Save or Preview using javascript when the button is clicked.

    Make sense?

  7. #7
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)

    Re: How to change button label without changing "value" attribute?

    Originally posted by hstraf
    I have the following input tags that create two buttons with the labels of "Save" and "Preview". When either button is pressed the same form is submitted and the "action" variable will have the apprpriate value depending on which button was pressed.

    Code:
    <input type="submit" name="action" value="Save" style="width:150px;">
    <input type="submit" name="action" value="Preview" style="width:150px;">
    Is it possible to redesign this code so that the buttons can have different labels, but the "action" variable will have the same values?

    In other words, I can't change the "Save" or "Preview" values for the action variable, but I need to display a different label on the button!

    Thanks for any help.
    Try this javascript function:
    Code:
    <script language="javascript" type="text/javascript">
    function submitForm(){
    if(document.form1.elements['action'].value=='Save'){
     document.form1.elements['action'].value='Changed-value!';
    }
     document.form1.submit();
    }
    </script>
    ...
    <!--input buttons-->
    <input type="button" name="action" value="Save" onClick="submitForm();" />
    <input type="button" name="action" value="Preview" onClick="submitForm();" />
    If your form is named 'form1', clicking on the "Save" button will change the action variable's value to "Changed-value!", then submit the form. Notice that the buttons are not "Submit" buttons anymore, but rather regular old buttons.

    Hope this helps!

    --Vinnie


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •