Page 1 of 1
if value == value 1 or value 2
Posted: Mon Feb 17, 2014 9:49 am
by jonnyfortis
i have 3 product code 958, 959 and 960
if either of the first are chosen i want to show one input type. if neither of these are shown i want another input type to show
have tried
<? if ($row_rsSize['StockID'] == '958' or '959'):
but obviously the or is incorrect
Code: Select all
<? if ($row_rsSize['StockID'] == '958' or '959'):
?>
<select name="Quantity[]" value="<?php echo $XCart_Quantity = ${$XCName}["contents"][3][$XCart__i]; ?>">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
(max: 3 caps per order)
<?php endif; ?>
<? if ($row_rsSize['StockID'] !== '958' or '959'):
?>
<input name="Quantity[]" type="text" value="<?php echo $XCart_Quantity = ${$XCName}["contents"][3][$XCart__i]; ?>" size="2" maxlength="2" />
<?php endif; ?>
Re: if value == value 1 or value 2
Posted: Mon Feb 17, 2014 9:54 am
by Celauran
Code: Select all
if ($row_rsSize['StockID'] == '958' || $row_rsSize['StockID'] == '959')
Re: if value == value 1 or value 2
Posted: Mon Feb 17, 2014 10:26 am
by jonnyfortis
Celauran wrote:Code: Select all
if ($row_rsSize['StockID'] == '958' || $row_rsSize['StockID'] == '959')
thats great thanks..however what seems to be happening and i dont know why is i am getting an extra text input
Code: Select all
<? if ($row_rsSize['StockID'] == '958' || $row_rsSize['StockID'] == '959'):
?>
<select name="Quantity[]" value="<?php echo $XCart_Quantity = ${$XCName}["contents"][3][$XCart__i]; ?>">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
(max: 3 caps per order)
<?php endif; ?>
<? if ($row_rsSize['StockID'] !== '958' || $row_rsSize['StockID'] == '959'):
?>
<input name="Quantity[]" type="text" value="<?php echo $XCart_Quantity = ${$XCName}["contents"][3][$XCart__i]; ?>" size="2" maxlength="2" />
<?php endif; ?>
there is another text box appearing directly after "(max: 3 caps per order)"
then the correct text box is showing if stock id 960 is showing
Re: if value == value 1 or value 2
Posted: Mon Feb 17, 2014 10:30 am
by Celauran
Code: Select all
if ($row_rsSize['StockID'] !== '958' || $row_rsSize['StockID'] == '959')
Are you sure this is what you meant? If it's not 958 or if it is 959?
Re: if value == value 1 or value 2
Posted: Mon Feb 17, 2014 10:33 am
by jonnyfortis
Celauran wrote:Code: Select all
if ($row_rsSize['StockID'] !== '958' || $row_rsSize['StockID'] == '959')
Are you sure this is what you meant? If it's not 958 or if it is 959?
sorry i meant if not either 958 or 959
Re: if value == value 1 or value 2
Posted: Mon Feb 17, 2014 10:40 am
by Celauran
So
Code: Select all
if ($row_rsSize['StockID'] != '958' && $row_rsSize['StockID'] != '959')
Re: if value == value 1 or value 2
Posted: Mon Feb 17, 2014 10:56 am
by jonnyfortis
brilliant. that done it the only thing that is happening now is when i confirm the select quantity as for example as 2 that the menu reverts back to 1 when i confirm. it isnt holding the value.
thanks
Re: if value == value 1 or value 2
Posted: Mon Feb 17, 2014 11:08 am
by Celauran
For that, you need to add selected="selected" to the selected entry.
Re: if value == value 1 or value 2
Posted: Mon Feb 17, 2014 11:37 am
by jonnyfortis
Celauran wrote:For that, you need to add selected="selected" to the selected entry.
sorry i sort of get what you mean but where does it go?
Re: if value == value 1 or value 2
Posted: Mon Feb 17, 2014 11:53 am
by Celauran
Try something like this
Code: Select all
<?php if ($row_rsSize['StockID'] == '958' || $row_rsSize['StockID'] == '959'): ?>
<?php $selected = ${$XCName}["contents"][3][$XCart__i]; ?>
<select name="Quantity[]">
<?php for ($i = 1; $i <= 3; $i++): ?>
<option value="<?= $i; ?>" <?= $selected == $i ? 'selected="selected"' : ''; ?>><?= $i; ?></option>
<?php endfor; ?>
</select>
(max: 3 caps per order)
<?php endif; ?>
Re: if value == value 1 or value 2
Posted: Mon Feb 17, 2014 1:47 pm
by jonnyfortis
Celauran wrote:Try something like this
Code: Select all
<?php if ($row_rsSize['StockID'] == '958' || $row_rsSize['StockID'] == '959'): ?>
<?php $selected = ${$XCName}["contents"][3][$XCart__i]; ?>
<select name="Quantity[]">
<?php for ($i = 1; $i <= 3; $i++): ?>
<option value="<?= $i; ?>" <?= $selected == $i ? 'selected="selected"' : ''; ?><?= $i; ?></option>
<?php endfor; ?>
</select>
(max: 3 caps per order)
<?php endif; ?>
brilliant thanks just added the end value tag >
Code: Select all
<option value="<?= $i; ?>" <?= $selected == $i ? 'selected="selected"' : ''; ?>><?= $i; ?></option>
and worked
thanks again
Re: if value == value 1 or value 2
Posted: Mon Feb 17, 2014 1:53 pm
by Celauran
I had a typo in there; forgot the closing > on option tag.
Re: if value == value 1 or value 2
Posted: Mon Feb 17, 2014 2:00 pm
by jonnyfortis
Celauran wrote:I had a typo in there; forgot the closing > on option tag.
yes found it. thanks for you help.