0

I am working on a website which is generating the 'Quantity' dropdown menu via PHP. I would like to change this to an input field instead so people can manually type in how many products they'd like to buy.

The original developer has the input field being made with PHP etc. I've pasted the code of how it's making the dropdown so you can see what needs changing. Just unsure what to change exactly. I've also pasted the link to the page it can be found on.

$frm_qty = new Select($db,'quantity['.$row_rsPO['optionName'].']','jq_qty',($_POST['quantity'][$row_rsPO['optionName']]?$_POST['quantity'][$row_rsPO['optionName']]:1),'');
for ($i=1;$i<=14; $i+=1 ) $frm_qty->newOption($i,$i);
$frm_qty->writeLabel(); $frm_qty->write(); 
?>

<input id="poOptionType" type="hidden" name="poOptionType" value="<?php echo $row_rsPO['optionType']; ?>" />
<?php echo '</td><td>&nbsp;</td>'; ?>

Not entirely sure if i've pasted enough here, so i've also copied all code into pastebin. I've pasted below what can be seen front end from view-source on the page.

HTML

    <form method="post" id="jq_form">
                                                                <label for="quantity[]"></label>
<select onblur="" name="quantity[]" id="quantity[]" class="jq_qty" onchange=""  style="" size="">
    <option value="1" selected="selected">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
</select>
<input id="poOptionType" type="hidden" name="poOptionType" value="" /></form>

live url - http://bit.ly/1bm02Kq

pastebin - http://pastebin.com/SpiJTwFw

1
  • poOp(..)Type hihi. But seriously: What have you tried? It seems like you can dump most of the pasted code and either manually print an input field or look for a class Input e.g. that your original programmer may have written just like he wrote Select Commented Nov 26, 2013 at 22:37

3 Answers 3

1

He's using an object with a funny name to generate the fields with an ternary operator... a real mess IMO

Why don't you just strip it all together and create a new input field like this?

<input type="number" name="quantity" placeholder = "0"  min="1" value = "<?= htmlentities($_POST['quantity']); ?>"/>

(Note the XSS injection avoided there)

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

Comments

1

If you want only to change it to a text input field, just remove this:

$frm_qty = new Select($db,'quantity['.$row_rsPO['optionName'].']','jq_qty',($_POST['quantity'][$row_rsPO['optionName']]?$_POST['quantity'][$row_rsPO['optionName']]:1),'');
for ($i=1;$i<=14; $i+=1 ) $frm_qty->newOption($i,$i);
$frm_qty->writeLabel(); $frm_qty->write(); 
?>

... and replace it with this:

<input type="text" name="quantity[]" id="quantity[]" class="jq_qty" />

Comments

0

Replace the select with:

<input type="text" name="quantity" id="quantity" size="8" />

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.