determine which submit input is clicked, get syntax error

Discussion in 'Javascript' started by, Jan 14, 2012.

  1. I have a question about the submit inputs. There are two filtered
    submit inputs that are independent of each other.
    I want to capture which one the user clicked. I get a syntax error on
    the asterisks.
    Firebug says "illegal character " at the end of the else if line.
    I think it may be because the
    onclicks submit buttons are outside the javascript or else the onclick
    needs to be a js function?
    I tried putting javascript tags around the form but I got the same
    exact error.
    The global var btnClicked needs to pick up the value of which submit
    button was clicked.
    Then the clkButton function return value should be passed to the
    getConfigURL function.
    It looks like it should work and just needs some clarity on the above.
    Thanks, JR
    <span id= "searchOrderNumber">
    Order Number: <input type="text" id="orderNumber" name="orderNumber"
    size="20" value="" />
    <input id="filterSearch" type="submit"
    value="Search" onclick="btnClicked=this" /></span>

    <li>End Date: <input type="text" id="endDate" name="endDate" /><input
    type="hidden" id="xmlEndDate" name="xmlEndDate" /></li>
    <li>EmpNo: <input type="text" id="EmpNo" name="EmpNo" size="4"
    value="" /></li>
    <li><input id="filterSubmit" type="submit" value="Submit"
    onclick="btnClicked=this" /></li>

    var btnClicked;// global var to see which filter selected, see input

    function clkButton() {
    var submit;
    if(btnClicked.value== 'Submit' ) {
    submit = 'submitFilter' ;
    }else if (btnClicked.value=='Search') { ​ ******stops here before
    it gets passed to next function
    submit = 'submitSearch' ;
    return submit;

    function getConfigURL(submitType,xmlStartDate, xmlEndDate) {
    if(submitType=="submitFilter") { //
    var plant = YAHOO.util.Dom.get("userPlant").value;
    var configURL = sent parameters in url to databasexxxxx
    }else if(submitType=="submitSearch"){ //
    var configURL = sent parameters in url to
    var orderNumber = YAHOO.util.Dom.get("orderNumber").value;
, Jan 14, 2012
    1. Advertisements

  2. How about posting a URL? It's rather awkward to try to debug code that
    has been munged by your Usenet posting software (lines broken etc.) and
    that does not constitute a full document.
    How about fixing the error then?
    You don't think that proper JavaScript code, do you?

    P.S. In your sender information on Usenet, it's not wise to use a fake
    name that coincides with the name of a reputable discussion list.
    Jukka K. Korpela, Jan 14, 2012
    1. Advertisements


    JRough Guest

    I fixed the hidden name issue, I had posted to a css group and somehow
    copied that group email adrs onto the javascript group in google
    groups? It was not intentional. The data is XML data delivered from
    SAP which can't be recreated. In any case, I have a web server at
    home so I put an example on

    I added a search box for the order number field, a single search for
    one order on one row, it is the first "search" button. The "submit"
    button filter was already there that allows filtering on all the
    fields returned in a table of data with nice drop downs etc from YUI
    and I could not recreate that here because it is all customized
    functions but you get the idea.

    I want the user to be able to select either filter button, they are
    mutually exclusive filters. I had it working but I noticed the
    previous "orderNumber" had to be cleared out of the field for the 2nd
    submit filter to work and vice versa so the user could do as many
    searches on either filter as necessary.
    The process of the page:
    The clickhandler2() function was added to capture the click event for
    the new "orderNumber" search filter. The configURL sends the URL to
    SAP and loads the XML data and creates a URL to be passed to SAP. I
    added the if{} else{} to this configURL() function and the submitType
    parameter passed to it to determine which filter was submitted.

    My idea on how to clear out the inputted data to start a new search
    was to add the clkButton event handler to check for which search
    button was clicked and pass it to the configURL(submitType) function
    instead of passing it to each clickHandler so the old data doesn't get
    in the way. It just checks which filter was submitted each time.
    This is what doesn't appear to be working and I think there is a
    simple reason why that I need some explanation on. I added the global
    var btnClicked, see the related form "btnClicked" This clkButton event
    is not really an event it is just HTML flag. Is that right? It
    doesn't need to be enclosed in <script type=javascript/text> tags? It
    seems like this is where the error is but I can't tell for sure so I
    am wondering if what I did is right? NOtice in the form that it isn't
    a click event it just picks up the submit click from the HTML then the
    function passes it to the configURL.
    Thanks very much,
    JRough, Jan 15, 2012
  4. Sorry, it does make much sense. What is it supposed to submit to, and
    why is the JavaScript code as text content there?

    It's not even obvious why you have two submit buttons in a <form>
    element that is not closed anywhere. Why not two separate forms, each
    with fields and submit buttons of their own? Then you would not need to
    worry about detecting client-side which button was clicked on.
    Jukka K. Korpela, Jan 15, 2012

    JRough Guest

    That is a good question but can't 100% explain everything on the real
    page except that YUI loader picks up the values in the inputs and
    strings them together in the configURL and then sends them via the
    illuminator string in configURL to SAP via the key and some loader
    functions. There is one string for each filter. There is actually no
    form in the original page that works on the one search. I just added
    the form to try to understand what is going on. I think YUI is using
    event functions. So are you saying this btnClicked() will not work?

    var configURL = "/XXXX/Illuminator?Transaction=" +
    XXX.config.GLOBAL_DIR + "/Message%20Queue/
    JRough, Jan 15, 2012

    JRough Guest

    About the Javascript code as text content, I thought it wasn't a real
    event but I guess the this keyword is a Javascript keyword. Ok maybe
    I am making it too difficult. If I could add two forms then I could
    test for which form was clicked but then why does it work with no
    form? I guess that must be the answer,but I was trying to do it the
    way it was done without a form not knowing why there is no form
    thinking it has something to do with YUI I don't understand. Thanks
    for your input,
    JRough, Jan 15, 2012

    JRough Guest

    Okay I created two forms with separate id's around the two separate
    searches. It appears that the string to the server is a GET post. I
    do get the value of which button was submitted? tnx,
    JRough, Jan 15, 2012
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.