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 4094362
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:44:07+00:00 2026-05-20T19:44:07+00:00

as before the below code is in a while loop . it out puts

  • 0

as before the below code is in a while loop . it out puts values id=pro0 then next loop through i get id=pro1 and if i have another record i get id=pro3

print "<td><input style=\"text-align:center\" type=\"text\" name=\"productitemsupdate_$num\" value=\"$row[productitems]\" size=\"5\" id=\"pro$num\"></td>";

the above code works with

var pro = document.getElementById('pro0');

what im after is a loop in java script which will take the last $num from the php from and use that for the amount of times to loop the javascript function.

something like this i think

var i=0;
while (i<=$num) {
    var pro[i] = document.getElementById('pro'[i]);
    if (pro[i].value == "") {
        inlineMsg('pro'[i],'This cannot Be blank'[i],10);
        return false;
    } else {
        i++;
    }
}

breaks when it is false when all fields are right it is true.
if i get this working it will save me guessing how many variable to check.

i have tried this but i cant this working either

var i=0;
var pro[i] = document.getElementById('pro' + i);
for(var i = 0; i < <?php $num ?>; i++) {
    if(pro[i].value == "")
        alert("You entered: " + pro[i].value)
    return false;
}

this works but only for the first line. if the 2nd line is emtpy and the first line is not it does not produce the alert

var i=0;
for(var i = 0; i < 3; i++) {
var pro = document.getElementById('pro' + i);
if(pro.value == "")
alert("You entered: " + pro[i].value)


return false;
}

i also changed the $num variable to a static number for my test record to see if it was my variable not being passed and it still did’t work for the 2nd record any ideas

thanks

steve

working solution thanks for your help

var i=0;
var pro = [];

for(var i = 0; i < 2; i++) {
pro[i] = document.getElementById('pro' + i);
if(pro[i].value == ""){
    alert("You entered: " + pro[i].value)
return false;}

}

  • 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-20T19:44:07+00:00Added an answer on May 20, 2026 at 7:44 pm

    In javascript, you concatenate strings using +. Therefore, you need to write

    pro[i] = document.getElementById('pro' + i);
    

    For your loop, that’d look something like

    for(var i = 0; i < <?php echo $num ?>; i++) {
    
        ...
    
    }
    

    Complete code:

    var i=0;
    var pro = [];
    for(var i = 0; i < <?php echo $num ?>; i++) {
        pro[i] = document.getElementById('pro' + i);
        if(pro[i].value == "") {
            alert("You entered: " + pro[i].value)
            return false;
        }
    }
    

    If you don’t need the actual array for anything, for later, you could simply do:

    var i=0;
    for(var i = 0; i < <?php echo $num ?>; i++) {
        var pro = document.getElementById('pro' + i);
        if(pro.value == "") {
            alert("You entered: " + pro.value)
            return false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a while loop that echos out several images. My next step is
Can somebody explain to me what the below code is doing. before and after
below is the code i'm using and i've used this 100x's before. And now
Below is a code snippet, where we retrieve a form value. Before further processing
If I run the function below before defining it, I will get this error...
I have a table trigger like below: CREATE OR REPLACE TRIGGER PAT_BUR_DOB_TRG BEFORE UPDATE
Please see the back trace below, I don´t think I have seen this before
I have a CSV file which the code below uses to put the contents
Please see the below code: I am have a table row defined using asp.net
BEFORE: EUTQQGOPED AFTER: EUT-QQG-OPED The example below is what I came up with to

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.