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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:43:27+00:00 2026-06-01T15:43:27+00:00

I have to ask this question because I’m stuck, and I think its because

  • 0

I have to ask this question because I’m stuck, and I think its because my understanding of PHP and JavaScript is not fully formed.
I think the way I’ve started to try doing this may be very very wrong but no one else’s question hits on something that makes sense to me.

Basicaly:
I’m trying to have a JavaScript button on a form that will add additional form input boxes and at the same time add additional SQL code in PHP for inserting the data from the new forms to my database.

My JavaScript looks like this..

    function addElement2() {

var ni = document.getElementById('SQLphoneDiv'); 
    var numi = document.getElementById('theValue2'); 
    var num = (document.getElementById('theValue2').value -1 + 2); 
    numi.value = num; 
    var newdiv = document.createElement('div'); 
    var divIdName = 'SQLphoneDiv'+num+''; 
    newdiv.setAttribute('id',divIdName); 
    newdiv.innerHTML = ' <input type=hidden id=' +num+ ' value=' +num+ '> <?php      $insert_phone = "INSERT INTO phone (Phone_Cust_ID,Phone_Numb,Ext) VALUES    (\'$cust_ID[0]\',\'".$_POST[\'phone' +num+ '\']."\',\'".$_POST[\'ext' +num+ '\']."\')";    $add_phone = mysql_query($insert_phone); ?>'; 
    ni.appendChild(newdiv); 
    }

The “newdiv.innerHTML” is where all the code is, and when my JavaScript runs it sends it to a DIV on my PHP page.

     <?php
    if (isset($_POST['submit'])) { 

         //add aditional phone numbers

         echo    '<input type="hidden"  value="0" id="theValue2" />';
         echo    '<div id="SQLphoneDiv"></div>';
     ?>

I’ve found that putting the echo parts outside of the “if” section makes the code actually show up when I hit my add button (at least the DIV’s show up, of course it shows no PHP in live mode on Dreamweaver).

So anyway, if I understand what I’m just figuring out this is totally wrong, because the PHP is set once the page is run, so trying to add more code after the fact makes no sense.
Am I thinking right on this? How would you actually do this? Something with AJAX?

Any tips are greatly appreciated.

Nathan

  • 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-01T15:43:28+00:00Added an answer on June 1, 2026 at 3:43 pm

    PHP runs on the server before the page is sent to the client. JavaScript runs on the client. AJAX would be the way to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this is not the appropriate site to ask this question, but I
I'm not really sure how to ask this question. Suppose I have a class
I ask this question because I've implemented a javascript solution to nested inlines (it
Not really sure how to ask this question because I really don't know what
I have to ask this question because I've never programmed except in an intro
I ask this question here because I think this is more a regex question
I have ask this kind of question before, but it seems my previous question
I have to really ask this question as I donot know Python. Following are
I ask this question in anticipation as part of a project. I have experience
[i meant to ask this question on StackOverflow...] I have been using VisualSVN Server

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.