Breaking input parameter for webservice call

In my index.html page, I have the following:

<div class="input-group">
   <input type="text" autocomplete="on" id="search-critera" class="form-control" aria-label="search criteria" placeholder="Enter name or ID number" />
       <div class="input-group-btn">
          <button type="button" class="btn btn-success" id="search-btn" onclick="search();">SEARCH</button>
         
      </div>
   </div>
   
   
   <script type="text/javascript">

        
        function search() {
		var enteredValue = $("#search-critera").val();
		
		if(isNaN(enteredValue)){
                alert("Please enter numeric value forID");
                return;
            }else{
                 
            jQuery.myapplication.app.setData("entered_search_text",enteredValue);
            }
           
		    jQuery.myapplication.app.setPage("my_test_page");
        };
       

       
       
    </script>

In my other javascript page, I am passing this parameter enteredValue for a webservice call (AJAX based) like the following :

var data = {
                ID:  enteredValue,
				first_name: firstName,
				last_name: lastName
				
		};

The firstName and lastName aren’t mandatory fields so the webservice call works file.

I am thinking to provide one more functionality for a user to enter in the search field in addition to the ID number, that is, firstName and lastName.
Is there a way I can split the full name entered by the user into firstName and lastName and then pass it to webservice call separately?

If you want to have a first and last name I think the best would be to not have a single full name text input.
You could do a split, but where would you split something like
“Sir Reginald Grant Clemency Jr.” ?
I suppose you could test it and give some type of “only two names allowed” error message, but IMHO it would be a lot cleaner to have two separate inputs.

Thanks for your reply. I am wondering even if I have an option of only single input, like for firstName or lastName, how would I differentiate between firstName and lastName in that scenario to make sure the webservice call receives the right parameter.

It would depend on what parameters were required.
Typically I think most expect an object or an array, most likely as JSON

I see. In the web service, right now, we don’t have any mandatory requirement for any parameters, so I can pass firstName and lastName both if I want to but just need to figure out a way to differentiate between the two.

function search() {
		var enteredValue = $("#search-critera").val();
       if(isNaN(enteredValue)){
                alert("Please enter numeric value forID");
                return;
            }else{
                 
            jQuery.myapplication.app.setData("entered_search_text",enteredValue);
            }
           
		    jQuery.myapplication.app.setPage("my_test_page");
        
       
        var firsName=prompt('Enter firstname');
        if(firsName===''){
          var firsName=prompt('Enter firstname');
        }
        var lastName=prompt('Enter lastname');
        if(lastName===''){
          var lastName=prompt('Enter lastname');
        }
} 

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.