Jump to content

extremely stuck


jake2891

Recommended Posts

Hi Guys,

 

I have a form with a drop down with values 1-5 and I need it that wen a user clicks on the value 1 then it automatically inserts a input field and 2 then inserts 2 fields etc.. here is a sample of my code. Only trouble im having is that its smarty based so need to do the looping somehow in html comment format.

 

html template source below

 

<script language="JavaScript" type="text/javascript">

    function showdivs() {

        totaldivs = document.forms.consult.sales.value;

        totaldivs++;

        for (j=1; j<6; j++) { document.getElementById("sales"+j).style.display = 'none'; }

        for (i=1; i<totaldivs; i++) { document.getElementById("sales"+i).style.display = 'block'; }

    }

</script>

 

 

<table>

      <tr>

        <td ><select name="sales" id="sales" class="formtext11" onChange="showdivs();">

                      <option value="0">Sales</option>

                      <option>1</option>

                      <option>2</option>

                      <option>3</option>

                      <option>4</option>

                      <option>5</option>

                      </select></td>

     

  <!-- {section loop=$divs name="divs" } -->

  <div name="sales{$i}" id="sales{$i}" style="display: none;">

  </tr>

<td><input name="sales_names{$i}"  /></td>

  </tr>

  </div>

  <!-- {/section} -->

 

</table>

 

 

php code source below dont think this is quite right.

 

$divs = range(1,6);

$smarty->assign("divs", $divs);

 

some how i need to loop through this eg.. "for div in divs" in the template and then the $i Iam stuck on aswel this needs to be sales_names1 , sales_names2, sales_names3 etc so that each time it displays the new field the field name is unique for posting.  Any help will be greatly appreciated.

 

Link to comment
Share on other sites

Sounds like you should be posting in the Javascript forum.

 

Maybe i was unclear the javascript in the html is all correct Its the looping through the php code that is the problem. Because

im using smarty I cant use php in the template so I need to loop through the php code in the template something like the following <!-- {section loop=$divs name="divs" } --> with the $divs corresponding to the php code but i dont think the php is quite rite any one know the answer? thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.