1

i have this issue. I am trying to create a form page where it will show a list of data using a while loop and each of them have the input field option to choose a date which will all be submitted over. So far i have about 4 fields displayed but the datepicker only works for the first one. The rest are just empty text box.

This my code :

$query = "SELECT * FROM application WHERE Shortlist_status = 1 ORDER BY Candidate_id ASC";
$result = mysqli_query($link, $query) or die(mysqli_error($link));

<html>
<head>

    <link href="stylesheet/style.css" rel="stylesheet"/>
    <script src="script/jquery-1.10.2.min.js"></script>
    <script src="script/jquery-ui-1.10.3.custom.min.js"></script>
    <link rel="stylesheet" href="stylesheet/jquery-ui-1.10.3.custom.min.css">


     <script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>   


</head>
    <title>
        Arrange interview
    </title>

<body>

while ($row = mysqli_fetch_array($result)) {

(Some other input data)

<input type="text" id="datepicker" name="date"/>

}

1 Answer 1

2

Use class datepicker instead of unique id:

$query = "SELECT * FROM application WHERE Shortlist_status = 1 ORDER BY Candidate_id ASC";
$result = mysqli_query($link, $query) or die(mysqli_error($link));

<html>
<head>

    <link href="stylesheet/style.css" rel="stylesheet"/>
    <script src="script/jquery-1.10.2.min.js"></script>
    <script src="script/jquery-ui-1.10.3.custom.min.js"></script>
    <link rel="stylesheet" href="stylesheet/jquery-ui-1.10.3.custom.min.css">


     <script>
$(function() {
$( ".datepicker" ).datepicker(); // Change this line
});
</script>   


</head>
    <title>
        Arrange interview
    </title>

<body>

while ($row = mysqli_fetch_array($result)) {

(Some other input data)

<input type="text" class="datepicker" name="date"/> // Change this line

}

Explanation:

An attribute id should have a unique value. You cannot define 4 datepicker with the same id datepicker. Instead, you should use the attribute class. Your JQuery's selector becomes then $('.datepicker').

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.