Welcome to TalkGraphics.com
Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Join Date
    Aug 2015
    Location
    A galaxy far far away
    Posts
    257

    Default Passing button ID

    Hello all,

    I want pass the ID (which I set through name) of a button to a function so I have added this snippet to the Link to web of the button

    javascript:validate_forms(this)


    but it doesn't pass the ID though, if I add it to the onclick event (though HTML) after the button ID is set then it works. Is there any way to explicitly set the button ID through the Link to web to pass it to the function?

  2. #2
    Join Date
    Apr 2012
    Location
    SW England
    Posts
    17,879

    Default Re: Passing button ID

    Quote Originally Posted by nazf355 View Post
    Hello all,
    I want pass the ID (which I set through name) of a button to a function so I have added this snippet to the Link to web of the button
    javascript:validate_forms(this)
    but it doesn't pass the ID though, if I add it to the onclick event (though HTML) after the button ID is set then it works. Is there any way to explicitly set the button ID through the Link to web to pass it to the function?
    javascript:alert(document.getElementById("buttonId ").id); works in the Link box for a Button with Name buttonId.

    • javascript:validate_forms(document.getElementById( "buttonId").id); should work for you.

    Acorn
    Acorn - installed Xara software: Cloud+/Pro+ and most others back through time (to CC's Artworks). Contact for technical remediation/consultancy for your web designs.
    When we provide assistance, your responses are valuable as they benefit the community. TG Nuggets you might like. Report faults: Xara Cloud+/Pro+/Magix Legacy; Xara KB & Chat

  3. #3
    Join Date
    Aug 2015
    Location
    A galaxy far far away
    Posts
    257

    Default Re: Passing button ID

    Quote Originally Posted by Acorn View Post
    javascript:alert(document.getElementById("buttonId ").id); works in the Link box for a Button with Name buttonId.

    • javascript:validate_forms(document.getElementById( "buttonId").id); should work for you.

    Acorn
    The problem with this is that I have 3 buttons (1 for each variant) and if I put this code in they will all end up with the same ID, buttonID. So what I need is to set the button ID through Names so that I can have different ID for each button and then dynamically pass it through the validate forms function so that I can have different validation depending on the button clicked.

  4. #4
    Join Date
    Apr 2012
    Location
    SW England
    Posts
    17,879

    Default Re: Passing button ID

    The Name "buttonId1" can be used on one form; "buttonId2" on a second and so on.
    When a button is clicked, the code finds the Named button and returns its ID.

    In passing, in Xara Namings, you should only ever give a Name to a single object.
    It would be different if you were using JavaScript as you could identify the button as a descendant of the specific form.

    Acorn
    Acorn - installed Xara software: Cloud+/Pro+ and most others back through time (to CC's Artworks). Contact for technical remediation/consultancy for your web designs.
    When we provide assistance, your responses are valuable as they benefit the community. TG Nuggets you might like. Report faults: Xara Cloud+/Pro+/Magix Legacy; Xara KB & Chat

  5. #5
    Join Date
    Aug 2015
    Location
    A galaxy far far away
    Posts
    257

    Default Re: Passing button ID

    Quote Originally Posted by Acorn View Post
    The Name "buttonId1" can be used on one form; "buttonId2" on a second and so on.
    When a button is clicked, the code finds the Named button and returns its ID.

    In passing, in Xara Namings, you should only ever give a Name to a single object.
    It would be different if you were using JavaScript as you could identify the button as a descendant of the specific form.

    Acorn
    I'm confused (easily done) that's not happening.
    The way I understand it you are calling the button ID based on the name?Both of which have to be set previously using right-click>Names?

  6. #6
    Join Date
    Apr 2012
    Location
    SW England
    Posts
    17,879

    Default Re: Passing button ID

    Quote Originally Posted by nazf355 View Post
    I'm confused (easily done) that's not happening.
    The way I understand it you are calling the button ID based on the name?Both of which have to be set previously using right-click>Names?
    You asked how to pass the information into your function.
    You could just as easily use javascript:validate_forms("buttonId1")...

    We may be at cross purposes here but you seem to want to indicate the button pressed for a specific form to validate against.
    So if that's all then the parameter passing can be as explicit or as programmatic as you like.

    Egg passed on a form solution elsewhere that is more for other Xara users.
    You are developing a very targeted need as your form is built by yourself and therefore limited in its wider applicability.

    TG isn't really a forum for JavaScript form development so to progress this I would ask that you advise the purpose of the form and provide an example of your design and where and what is not working, otherwise this thread will turn into a JavaScript ping-pong.

    Acorn
    Acorn - installed Xara software: Cloud+/Pro+ and most others back through time (to CC's Artworks). Contact for technical remediation/consultancy for your web designs.
    When we provide assistance, your responses are valuable as they benefit the community. TG Nuggets you might like. Report faults: Xara Cloud+/Pro+/Magix Legacy; Xara KB & Chat

  7. #7
    Join Date
    Aug 2015
    Location
    A galaxy far far away
    Posts
    257

    Default Re: Passing button ID

    Quote Originally Posted by Acorn View Post
    You asked how to pass the information into your function.
    You could just as easily use javascript:validate_forms("buttonId1")...


    Acorn
    Ah but I can't there in lies the crux of the matter. This is because of the way that variants and live sharing works in Xara. If I add that to one form button it will repeat across all the buttons in the variants.
    What I am trying to do is to have 3 forms wide, desktop, mobile, each one has a button with specific id form_button_wide, form_button_desktop, form_button_mobile, then when one is clicked it's ID is used to call a validation function specific for that form using Switch like so.

    Code:
    function validate_forms(clicked_id) {
    
    switch (clicked_id) {
    
        case "btn_newsletter_wide":
             validate_form_newsletter_wide(form);
             break;
    
        case "btn_newsletter_desktop":
             validate_form_newsletter_desktop(form);
             break;
    
        case "btn_newsletter_mobile":
             validate_form_newsletter_mobile(form);
             break;
    
        default:
        	alert(clicked_id);
    
    }
    
    
    }
    In javascript it is easy to do as you can set the ID before an onclick event, but in Xara when you set an ID it comes after the Link to where the call is made causing an error. I really just need to send something unique from each form to triggers it's specific validation. Hope that makes more sense.

  8. #8
    Join Date
    Aug 2015
    Location
    A galaxy far far away
    Posts
    257

    Default Re: Passing button ID

    I thought I had it I tried to put this code into the Names box;

    btn_newsletter_wide onclick="validate_forms(thi.id)"

    but in the source code it come out with dec code like this;

    id="btn_newsletter_wide:32onclick:61:34validate_fo rms:40thi.id:41:34"


    anyone know how to make the code actual characters as typed?

  9. #9
    Join Date
    Apr 2015
    Location
    Germany
    Posts
    927

    Default Re: Passing button ID

    Not sure if that is what you are looking for. "this" just doesn't work in href, so you have to modify it. Have a look at the attached example.
    Attached Files Attached Files

  10. #10
    Join Date
    Aug 2015
    Location
    A galaxy far far away
    Posts
    257

    Default Re: Passing button ID

    Quote Originally Posted by siran View Post
    Not sure if that is what you are looking for. "this" just doesn't work in href, so you have to modify it. Have a look at the attached example.
    How did you add the javascript code to this example?

 

 

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
  •