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

  • Home
  • SEARCH
  • 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 9169109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:47:38+00:00 2026-06-17T15:47:38+00:00

I have a script that would change the value of a input field: <script

  • 0

I have a script that would change the value of a input field:

    <script language="javascript">
    function klientid() {
    var getid = document.getElementById("getidfromsearch");//results
    var klid = document.getElementById("idklienta"); //input field
    if(getid != "0") {
    klid.value = getid.textContent;
    }
    </script>

a search engine and this is how results are printed:

    <?php
    while($rowmilion = mysqli_fetch_array($resultmilion)) {
    ?>
    <a href="javascript:klientid()">
    <table>
    <tr>
    <td style="font-weight:bold; width: 160px; text-align:right;">ID:</td>
    <td style="width:200px;" id="getidfromsearch"><?php echo $rowmilion['id']; ?></td>
    </tr>
    </table>
    </a>
    <?php } ?>

Now, when as the result there is only one record and I click on the link, it does change the value of a input field fine.

When result consists of more than one record, whichever link I would click, it will always get the value from the first record for example:

ID: 100
ID: 200
ID: 300

So when I click on the third position, it will still change the value of a input field to 100 instead of 300.

I quess, this is because all records get the same “ID”… But still, I can’t make it work.

  • 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-06-17T15:47:40+00:00Added an answer on June 17, 2026 at 3:47 pm

    You should give an unique ID for each result or it will screw up your getElementById search.

    Your JS code :

    <script language="javascript">
        function klientid(domElmtId) {// ** I added a parameter
            var getid = document.getElementById(domElmtId);//results
            var klid = document.getElementById("idklienta"); //input field
            if(getid !== null) {// ** This is better
                klid.value = getid.textContent;
            }
        </script>
    

    Your Php code

    <?php
        $count = 0;//** I added a variable to give each result a different ID
        while($rowmilion = mysqli_fetch_array($resultmilion)) {
        ?>
        <a href="javascript:klientid('result<?php echo $count; ?>')">
        <table>
        <tr>
        <td style="font-weight:bold; width: 160px; text-align:right;">ID:</td>
        <td style="width:200px;" id="result<?php ?>"><?php echo $rowmilion['id']; ?></td>
        </tr>
        </table>
        </a>
        <?php 
        $count += 1;//** to make different IDs
    } ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: <script type=text/javascript> function changestate() { var StateTextBox = document.getElementById(State); var
How can I write a script that will change an input field's text value,
I would like to change the value of an input field when the form
I need to have script.sh , that would create files f1.txt and f2.txt with
I have a script that sends emails to a contact list. I would like
I have a list of image paths in my PHP script that I would
I have a script with a factory method that I would like to return
I have the following jQuery script: $(document).ready(function() { $.ajax({ url: 'temp.ajax.php', type: 'GET', success:
I have an input field which I would like to dynamically validate while user
I have php scripts that do things like register, login, upload. I would like

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.