Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6385639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:55:30+00:00 2026-05-25T02:55:30+00:00

I was wondering how would i get like an id value so i could

  • 0

I was wondering how would i get like an id value so i could do something like this, I have 2 fields and a div (status).

<input name="item_1" type="hidden" value="1" /> 
<input type="text" name="date_1" id="dateselect" onchange="check();" />
<div id="status_1">Click on the field above!</div> 

<input name="item_2" type="hidden" value="2" /> 
<input type="text" name="date_2" id="dateselect" onchange="check();" />
<div id="status_2">Click on the field above!</div>

The value in the hidden field will be the same number for likes of item_x and date_x etc. that is 2 sets of field and there would be alot more! coded with PHP (foreach item).

So i need to pass the values of these fields into a ajax request.

date = $("[name='date']").val();
item = $("[name='item']").val();
elm = "#status";

How would i get the “1” or “2” as a var called id, so i could do something like

date = $("[name='date_"+id+"']").val();
item = $("[name='item_"+id+"']").val(); or item = id;
elm = "#status_"+id;

Since there will be multiple of these mini checkers, doing the same but not at the same time, only when clicked. I can easily do it when there is only 1 but when there is like more then 1 im a little stuck.

Heres my version of it doing it once, i need to some how set the id, so its no longer undefined:

function check(id,elm) {
book = $("[name='date']").val();
var item = '';
if(id === undefined){
item = $("[name='item']").val();
}else{
item = id;
}
if(elm === undefined){
elm = "#status";
}
if(book.length >= 3 && item.length >= 0) {
$(elm).html('<img align="middle" src="images/loading.gif" alt="Checking" /> Checking availability...');
$.ajax({type: "POST",url: "checker.php",data: "date="+book+"&itemid="+item,success: function(msg){
$(elm).ajaxComplete(function(event, request, settings){
if(msg == 'OK') {
$(elm).html(' <img align="middle" src="images/tick.png" alt="Available" /> Available!');
$(elm).next().val(1);
} else { 
$(elm).html(msg);
$(elm).next().val(0);}
});
}});
} else {
$(elm).html('');
}
}

Thanks for any help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:55:31+00:00Added an answer on May 25, 2026 at 2:55 am

    Based on your markup without the onchange event

    <input name="item_1" type="hidden" value="1" /> 
    <input type="text" name="date_1" id="dateselect" />
    <div id="status_1">Click on the field above!</div> 
    
    <input name="item_2" type="hidden" value="2" /> 
    <input type="text" name="date_2" id="dateselect" />
    <div id="status_2">Click on the field above!</div>
    

    You can let jQuery do the event wiring, for starters, and use the proper event (onkeypress or onblur would be best, I think)

    $(function(){
        // bind the onkeypress event to textboxes that start with 'date_'
        $("input:text[name^='date_']").onkeypress(function(){
            var id = $(this).attr("name").split("_")[1];
    
            var $date = $(this);
            var $item = $("[name='item_" + id + "']");
            var $status = $("#status_" + id);
    
            if($date.val().length >= 3 && $item.length > 0) {
                $status.html('<img align="middle" src="images/loading.gif" alt="Checking" /> Checking availability...');
                $.ajax({
                    type: "POST", 
                    url: "checker.php",
                    data: "date=" + $date.val() + "&itemid=" + $item.val(),
                    success: function(msg) {
                        if(msg == 'OK') {
                            $status.html('<img align="middle" src="images/tick.png" alt="Available" /> Available!');
                            $item.val(1);
                        } else { 
                            $status.html(msg);
                            $item.val(0);
                        }
                    }
                });
            } 
            else {
                $status.html('');
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering how you would approach this problem I have two Taxrates that
I'm wondering whether something like this is possible (and relatively easy to do), and
I was wondering if in Java I would get any odd behaviour if I
I have run a few using batch jobs, but, I am wondering what would
Just wondering how you would go about implementing something similar to stackoverflow'd related questions.
I would like to offer a webservice via JSONP and was wondering, if I
Was wondering how you would be able to test the input that is saved
I was wondering whether anybody here could help with this problem I am having
I'm wondering what Data Structure people would recommend to do the following. I have
I have a program written in python, and I would like to make it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.